1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.VimIMContext; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.IMContext; 33 private import gtk.TextIter; 34 private import sourceview.View; 35 private import sourceview.c.functions; 36 public import sourceview.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * Vim emulation. 42 * 43 * The `GtkSourceVimIMContext` is a [class@Gtk.IMContext] implementation that can 44 * be used to provide Vim-like editing controls within a [class@View]. 45 * 46 * The `GtkSourceViMIMContext` will process incoming [class@Gdk.KeyEvent] as the 47 * user types. It should be used in conjunction with a [class@Gtk.EventControllerKey]. 48 * 49 * Various features supported by `GtkSourceVimIMContext` include: 50 * 51 * - Normal, Insert, Replace, Visual, and Visual Line modes 52 * - Support for an integrated command bar and current command preview 53 * - Search and replace 54 * - Motions and Text Objects 55 * - History replay 56 * - Jumplists within the current file 57 * - Registers including the system and primary clipboards 58 * - Creation and motion to marks 59 * - Some commonly used Vim commands 60 * 61 * It is recommended that applications display the contents of 62 * [property@VimIMContext:command-bar-text] and 63 * [property@VimIMContext:command-text] to the user as they represent the 64 * command-bar and current command preview found in Vim. 65 * 66 * `GtkSourceVimIMContext` attempts to work with additional [class@Gtk.IMContext] 67 * implementations such as IBus by querying the [class@Gtk.TextView] before processing 68 * the command in states which support it (notably Insert and Replace modes). 69 * 70 * ```c 71 * GtkEventController *key; 72 * GtkSourceView *view; 73 * GtkIMContext *im_context; 74 * 75 * view = gtk_source_view_new (); 76 * im_context = gtk_source_vim_im_context_new (); 77 * key = gtk_event_controller_key_new (); 78 * 79 * gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (key), im_context); 80 * gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE); 81 * gtk_widget_add_controller (GTK_WIDGET (view), key); 82 * 83 * g_object_bind_property (im_context, "command-bar-text", command_bar_label, "label", 0); 84 * g_object_bind_property (im_context, "command-text", command_label, "label", 0); 85 * ``` 86 * 87 * Since: 5.4 88 */ 89 public class VimIMContext : IMContext 90 { 91 /** the main Gtk struct */ 92 protected GtkSourceVimIMContext* gtkSourceVimIMContext; 93 94 /** Get the main Gtk struct */ 95 public GtkSourceVimIMContext* getVimIMContextStruct(bool transferOwnership = false) 96 { 97 if (transferOwnership) 98 ownedRef = false; 99 return gtkSourceVimIMContext; 100 } 101 102 /** the main Gtk struct as a void* */ 103 protected override void* getStruct() 104 { 105 return cast(void*)gtkSourceVimIMContext; 106 } 107 108 /** 109 * Sets our main struct and passes it to the parent class. 110 */ 111 public this (GtkSourceVimIMContext* gtkSourceVimIMContext, bool ownedRef = false) 112 { 113 this.gtkSourceVimIMContext = gtkSourceVimIMContext; 114 super(cast(GtkIMContext*)gtkSourceVimIMContext, ownedRef); 115 } 116 117 118 /** */ 119 public static GType getType() 120 { 121 return gtk_source_vim_im_context_get_type(); 122 } 123 124 /** */ 125 public this() 126 { 127 auto __p = gtk_source_vim_im_context_new(); 128 129 if(__p is null) 130 { 131 throw new ConstructionException("null returned by new"); 132 } 133 134 this(cast(GtkSourceVimIMContext*) __p, true); 135 } 136 137 /** 138 * Executes @command as if it was typed into the command bar by the 139 * user except that this does not emit the 140 * [signal@VimIMContext::execute-command] signal. 141 * 142 * Params: 143 * command = the command text 144 * 145 * Since: 5.4 146 */ 147 public void executeCommand(string command) 148 { 149 gtk_source_vim_im_context_execute_command(gtkSourceVimIMContext, Str.toStringz(command)); 150 } 151 152 /** 153 * Gets the current command-bar text as it is entered by the user. 154 * 155 * Returns: A string containing the command-bar text 156 * 157 * Since: 5.4 158 */ 159 public string getCommandBarText() 160 { 161 return Str.toString(gtk_source_vim_im_context_get_command_bar_text(gtkSourceVimIMContext)); 162 } 163 164 /** 165 * Gets the current command text as it is entered by the user. 166 * 167 * Returns: A string containing the command text 168 * 169 * Since: 5.4 170 */ 171 public string getCommandText() 172 { 173 return Str.toString(gtk_source_vim_im_context_get_command_text(gtkSourceVimIMContext)); 174 } 175 176 /** 177 * Requests the application open the file found at @path. 178 * 179 * If @path is %NULL, then the current file should be reloaded from storage. 180 * 181 * This may be executed in relation to the user running the 182 * `:edit` or `:e` commands. 183 * 184 * Params: 185 * view = the #GtkSourceView 186 * path = the path if provided, otherwise %NULL 187 * 188 * Since: 5.4 189 */ 190 gulong addOnEdit(void delegate(View, string, VimIMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 191 { 192 return Signals.connect(this, "edit", dlg, connectFlags ^ ConnectFlags.SWAPPED); 193 } 194 195 /** 196 * The signal is emitted when a command should be 197 * executed. This might be something like `:wq` or `:e <path>`. 198 * 199 * If the application chooses to implement this, it should return 200 * %TRUE from this signal to indicate the command has been handled. 201 * 202 * Params: 203 * command = the command to execute 204 * 205 * Returns: %TRUE if handled; otherwise %FALSE. 206 * 207 * Since: 5.4 208 */ 209 gulong addOnExecuteCommand(bool delegate(string, VimIMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 210 { 211 return Signals.connect(this, "execute-command", dlg, connectFlags ^ ConnectFlags.SWAPPED); 212 } 213 214 /** 215 * Requests that the application format the text between 216 * @begin and @end. 217 * 218 * Params: 219 * begin = the start location 220 * end = the end location 221 * 222 * Since: 5.4 223 */ 224 gulong addOnFormatText(void delegate(TextIter, TextIter, VimIMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 225 { 226 return Signals.connect(this, "format-text", dlg, connectFlags ^ ConnectFlags.SWAPPED); 227 } 228 229 /** 230 * Requests the application save the file. 231 * 232 * If a filename was provided, it will be available to the signal handler as @path. 233 * This may be executed in relation to the user running the `:write` or `:w` commands. 234 * 235 * Params: 236 * view = the #GtkSourceView 237 * path = the path if provided, otherwise %NULL 238 * 239 * Since: 5.4 240 */ 241 gulong addOnWrite(void delegate(View, string, VimIMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 242 { 243 return Signals.connect(this, "write", dlg, connectFlags ^ ConnectFlags.SWAPPED); 244 } 245 }